package com.yxinsur.imc.web.controller.business;

import java.util.List;

import com.yxinsur.imc.business.form.AssessmentDetailForm;
import com.yxinsur.imc.business.form.AssessmentForm;
import com.yxinsur.imc.business.service.IImcAssessmentDetailService;
import com.yxinsur.imc.business.service.IImcAssessmentMetaService;
import com.yxinsur.imc.business.vo.AssessmentDetailVo;
import com.yxinsur.imc.business.vo.AssessmentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxinsur.imc.common.annotation.Log;
import com.yxinsur.imc.common.core.controller.BaseController;
import com.yxinsur.imc.common.core.domain.AjaxResult;
import com.yxinsur.imc.common.enums.BusinessType;
import com.yxinsur.imc.business.domain.ImcAssessment;
import com.yxinsur.imc.business.service.IImcAssessmentService;
import com.yxinsur.imc.common.utils.poi.ExcelUtil;
import com.yxinsur.imc.common.core.page.TableDataInfo;

/**
 * 考核主Controller
 * 
 * @author imc
 * @date 2021-06-10
 */
@Api(value = "考核模块服务接口",tags = "12.考核模块服务接口")
@RestController
@RequestMapping("/business/assessment")
public class ImcAssessmentController extends BaseController
{
    @Autowired
    private IImcAssessmentService imcAssessmentService;
    @Autowired
    private IImcAssessmentDetailService imcAssessmentDetailService;
    @Autowired
    private IImcAssessmentMetaService imcAssessmentMetaService;

    /**
     * 查询考核主列表
     */
    @ApiOperation("考核主批次数据分页查询")
    @GetMapping("/list")
    public TableDataInfo list(AssessmentForm assessmentForm)
    {
        startPage();
        List<AssessmentVo> list = imcAssessmentService.selectImcAssessmentList(assessmentForm);
        return getDataTable(list);
    }

    /**
     * 查询考核详情列表
     */
    @ApiOperation("查询考核详情分页列表查询")
    @GetMapping("/{assessmentId}/detail/list")
    public TableDataInfo detaillist(@PathVariable Long assessmentId, AssessmentDetailForm assessmentDetailForm)
    {
        startPage();
        List<AssessmentDetailVo> list = imcAssessmentDetailService.selectImcAssessmentDetailList(assessmentId,assessmentDetailForm);
        return getDataTable(list);
    }

    /**
     * 导出考核主列表
     */
    @ApiOperation("考核主批次数据导出")
    @GetMapping("/export")
    public AjaxResult export(AssessmentForm assessmentForm)
    {
        List<AssessmentVo> list = imcAssessmentService.selectImcAssessmentList(assessmentForm);
        ExcelUtil<AssessmentVo> util = new ExcelUtil<AssessmentVo>(AssessmentVo.class);
        return util.exportExcel(list, "assessment");
    }

    /**
     * 执行考核
     */
    @ApiOperation("执行考核")
    @PostMapping
    public AjaxResult excuteAssessment(@RequestBody AssessmentForm assessmentForm)
    {
        return AjaxResult.success("考核完毕，考核人数"+imcAssessmentService.excuteAssessment(assessmentForm)+"人");
    }

    /**
     * 执行考核
     */
    @ApiOperation("考核版本列表")
    @PostMapping("/versions")
    public AjaxResult versions()
    {
        return AjaxResult.success(this.imcAssessmentMetaService.selectAssessmentMetaList());
    }

    /**
     * 删除考核主
     */
    @ApiOperation("批量删除/撤销本次考核")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imcAssessmentService.deleteImcAssessmentByIds(ids));
    }
}
